package com.lindroy.androidplayer.ui.knowledge

import android.content.Context
import com.lindroy.androidplayer.R
import com.lindroy.androidplayer.base.BaseActivity
import com.lindroy.androidplayer.extensions.initColor
import com.lindroy.androidplayer.logic.model.KnowledgeItemResp
import com.lindroy.androidplayer.ui.adapter.BaseTabAdapter
import com.lindroy.androidplayer.ui.adapter.KnowledgeTabAdapter
import com.lindroy.lib_utils.extensions.extraParam
import com.lindroy.lib_utils.extensions.extraParcelable
import com.lindroy.lib_utils.extensions.getResString
import com.lindroy.lib_utils.extensions.launchActivity
import com.orhanobut.logger.Logger
import com.youngfeng.snake.annotations.EnableDragToClose
import kotlinx.android.synthetic.main.activity_knowledge_detail.*
import kotlinx.android.synthetic.main.fragment_wx_article.*
import kotlinx.android.synthetic.main.tablayout.*

/**
 * @author Lin
 * @date 2021/4/29
 * @function 体系详情页
 * @Description
 */
private const val KEY_KNOWLEDGE_DATA = "knowledge_data"
private const val KEY_SELECTED_INDEX = "selected_index"
private const val KEY_Title = "title"

@EnableDragToClose
class KnowledgeDetailActivity(override val layoutId: Int = R.layout.activity_knowledge_detail) :
    BaseActivity() {

    private val knowledgeList by lazy {
        intent.getSerializableExtra(KEY_KNOWLEDGE_DATA) as List<KnowledgeItemResp>
    }

    private val selectedIndex by extraParam(KEY_SELECTED_INDEX,0)

    private val title by extraParam(KEY_Title, getResString(R.string.app_name))

    private val tabAdapter by lazy {

        KnowledgeTabAdapter(
            knowledgeList.map {
                BaseTabAdapter.TabBean(it.id, it.name)
                              },
            supportFragmentManager
        )
    }

    override fun initView() {
        initToolBar(title)
        vpKnowledge.adapter = tabAdapter
        vpKnowledge.offscreenPageLimit = knowledgeList.size
        vpKnowledge.currentItem = selectedIndex
        tabLayout.setupWithViewPager(vpKnowledge)
    }

    override fun initData() {

    }

    override fun initListener() {

    }

    override fun initClick() {
    }

    companion object {
        fun start(context: Context, data: List<KnowledgeItemResp>,title:String, selectedIndex: Int) {
            context.launchActivity<KnowledgeDetailActivity>(
                KEY_KNOWLEDGE_DATA to data,
                KEY_Title to title,
                KEY_SELECTED_INDEX to selectedIndex
            )
        }
    }
}